﻿using DotNetMVC.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace DotNetMVC.IDAL
{
    public partial interface IBaseDal<T> where T : BaseEntity
    {
        #region 查询
        /// <summary>
        /// 获取所有没有软删除的数据
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAll();

        /// <summary>
        /// 获取总数据条数
        /// </summary>
        /// <returns></returns>
        long GetTotalCount();

        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="startIndex"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        IQueryable<T> GetPagedData(int startIndex, int count);

        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="total"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        IQueryable<T> GetPagedData(IQueryable<T> entities, out long total, int pageIndex, int pageSize);

        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <typeparam name="S"></typeparam>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="total"></param>
        /// <param name="whereLambda"></param>
        /// <param name="orderByLambda"></param>
        /// <param name="isAsc"></param>
        /// <returns></returns>
        IQueryable<T> GetPagedData<S>(int pageSize, int pageIndex, out int total,
            Expression<Func<T, bool>> whereLambda,
            Expression<Func<T, S>> orderByLambda,
            bool isAsc);

        /// <summary>
        /// 查找id=id的数据，如果找不到返回null
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T GetById(long id);
        #endregion

        #region CUD
        void MarkDeleted(long id);
        void MarkDeleted(T entity);
        void Deleted(T entity);

        void Add(T entity);
        void Update(T entity);
        #endregion
    }
}
